package com.ruoyi.wechat.config;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 微信配置类
 * 
 * @author ruoyi
 */
@Configuration
public class WxConfig
{
    @Value("${wx.mp.app-id}")
    private String appId;

    @Value("${wx.mp.app-secret}")
    private String appSecret;

    @Value("${wx.mp.token}")
    private String token;

    @Value("${wx.mp.aes-key}")
    private String aesKey;

    /**
     * 微信公众号配置存储
     */
    @Bean
    public WxMpConfigStorage wxMpConfigStorage()
    {
        WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
        config.setAppId(appId);
        config.setSecret(appSecret);
        config.setToken(token);
        config.setAesKey(aesKey);
        return config;
    }

    /**
     * 微信公众号服务
     */
    @Bean
    public WxMpService wxMpService(WxMpConfigStorage wxMpConfigStorage)
    {
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage);
        return wxMpService;
    }
}
